﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;
using VOL.Core.BaseProvider;
using VOL.Core.Extensions;
using VOL.Entity;
using VOL.SmartMecial.Dtos;
using VOL.SmartMecial.Infrastructure;
using VOL.SmartMecial.IServices.EvaluateNurseCare;

namespace VOL.SmartMecial.Services.EvaluateNurseCare
{
    public class InAssessServices : IInAssessServices
    {
        private readonly IBaseRepository<Entity.DomainModels.InAssess> _inAssessRep;

        public InAssessServices(IBaseRepository<Entity.DomainModels.InAssess> inAssessRep)
        {
            _inAssessRep = inAssessRep;
        }
        /// <summary>
        /// 添加入院表单
        /// </summary>
        /// <param name="inAssess"></param>
        /// <returns></returns>
        public async Task<int> AddInAssess(Entity.DomainModels.InAssess inAssess)
        {
            var result = await _inAssessRep.AddAsync(inAssess);
            return result;
        }
        /// <summary>
        /// 显示入院评估表单
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task<ApiPaging<Entity.DomainModels.InAssess>> ShowInAssess(PageDTO pageDto)
        {
            var result = new ApiPaging<Entity.DomainModels.InAssess>();
            var inAssessList = _inAssessRep.GetAll();
            result.TotalCount = inAssessList.Count();
            result.TotalPage = (int)Math.Ceiling(result.TotalCount * 1.0 / pageDto.pageSize);
            result.Items = inAssessList.OrderByDescending(x => x.Id).Skip((pageDto.pageIndex - 1) * pageDto.pageSize).Take(pageDto.pageSize).ToList();
            return await Task.FromResult(result);

        }

        /// <summary>
        /// 获取所有入单评估数据
        /// </summary>
        /// <returns></returns>
        public async Task<List<Entity.DomainModels.InAssess>> GetAllInAssess() 
        {
            var inAssesslist =  _inAssessRep.GetAll();
            return await Task.FromResult(inAssesslist.ToList());
        }
    }
}
